package com.swak.frame.filter.adapter;

import java.util.List;

import com.swak.frame.chain.FilterChain;
import com.swak.frame.chain.FilterChainFactory;
import com.swak.frame.context.BoundContext;
import com.swak.frame.filter.ApiFilter;

/**
 * SPI责任链模式工厂
 * 
 * @author colley.ma
 * @date 2018/04/17
 */
public class ApiFilterChainFactoryAdapter implements FilterChainFactoryAdapter<BoundContext> {

    private List<ApiFilter> apiFilters;

    private FilterChain<BoundContext> filterChain;

    public ApiFilterChainFactoryAdapter() {};

    public ApiFilterChainFactoryAdapter(List<ApiFilter> apiFilters) {
        this.apiFilters = apiFilters;
    }

    @Override
    public FilterChain<BoundContext> getFilterChain() {
        if (this.filterChain == null) {
            this.filterChain = FilterChainFactory.buildFilterChain(apiFilters);
        }
        return this.filterChain;
    }
}
